package ${sourceBasePackage}.service.impl;

import ${sourceBasePackage}.common.entity.${className};
import ${sourceBasePackage}.common.api.Page;
import ${sourceBasePackage}.common.api.PageData;
import ${sourceBasePackage}.service.${className}Service;
import ${sourceBasePackage}.mapper.${className}Mapper;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

/**
 *
 * @author:
 * <pre>
 * 	${author}
 * </pre>
 * @description: ${description}service实现类.
 * @data: ${createDate}
 * @copyright: zooocloud.com
 *
 */
@Service("${className?uncap_first}Service")
public class ${className}ServiceImpl implements ${className}Service {

	@Resource
	private ${className}Mapper ${className?uncap_first}Mapper;

	// 分页查询
	@Override
	public List<${className}> findByPage(Page page) throws Exception {
		return ${className?uncap_first}Mapper.findListPage(page);
	}

	// 根据实体类搜索
	@Override
	public List<${className}> findBySearch(${className} ${className?uncap_first}) throws Exception {
		return ${className?uncap_first}Mapper.find(${className?uncap_first});
	}

	// 根据Map搜索
	@Override
	public List<${className}> findBySearch(PageData pd) throws Exception {
		return ${className?uncap_first}Mapper.findWithPd(pd);
	}

	// 根据id查询
	@Override
	public ${className} getById(${pkType} ${pkField}) throws Exception {
		return ${className?uncap_first}Mapper.getById(${pkField});
	}

	// 添加所有
	@Override
	public ${className} addAll(${className} ${className?uncap_first}) throws Exception {
		if(${className?uncap_first}.getCreateTime()==null){
			${className?uncap_first}.setCreateTime(new Date());
		}
		if(${className?uncap_first}.getUpdateTime()==null){
			${className?uncap_first}.setUpdateTime(new Date());
		}
		${className?uncap_first}Mapper.add(${className?uncap_first});
		return ${className?uncap_first}Mapper.getById(${className?uncap_first}.get${pkField?cap_first}());
	}

	// 添加实体类
	@Override
	public ${className} add(${className} ${className?uncap_first}) throws Exception {
		if(${className?uncap_first}.getCreateTime()==null){
			${className?uncap_first}.setCreateTime(new Date());
		}
		if(${className?uncap_first}.getUpdateTime()==null){
			${className?uncap_first}.setUpdateTime(new Date());
		}
		${className?uncap_first}Mapper.addNotNull(${className?uncap_first});
		return ${className?uncap_first}Mapper.getById(${className?uncap_first}.get${pkField?cap_first}());
	}

	// 添加Map
	@Override
	public void add(PageData pd) throws Exception {
		if(!pd.containsKey("createTime")){
			pd.put("createTime", new Date());
		}
		if(!pd.containsKey("updateTime")){
			pd.put("updateTime", new Date());
		}
		${className?uncap_first}Mapper.addWithPd(pd);
	}

	// 更新实体类
	@Override
	public ${className} update(${className} ${className?uncap_first}) throws Exception {
		if(${className?uncap_first}.getUpdateTime()==null){
			${className?uncap_first}.setUpdateTime(new Date());
		}
		${className?uncap_first}Mapper.updateNotNull(${className?uncap_first});
		return ${className?uncap_first}Mapper.getById(${className?uncap_first}.get${pkField?cap_first}());
	}

	// 更新Map
	@Override
	public void update(PageData pd) throws Exception {
		if(!pd.containsKey("updateTime")){
			pd.put("updateTime", new Date());
		}
		${className?uncap_first}Mapper.updateWithPd(pd);
	}

	// 根据id删除
	@Override
	public void delete(${pkType} ${pkField}) throws Exception {
		${className?uncap_first}Mapper.delete(${pkField});
	}

	// 批量删除
 	@Override
	public void batchDelete(List<${pkType}> ${pkField}s) throws Exception {
		${className?uncap_first}Mapper.batchDelete(${pkField}s);
	}
}